package com.zyg.jas.studentport.controller;

import com.zyg.jas.common.pojo.Article;
import com.zyg.jas.common.pojo.Resources;
import com.zyg.jas.studentport.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/sport/article")
@CrossOrigin
public class ArticleController {
    private static final Logger logger = LoggerFactory.getLogger(ArticleController.class);
    @Autowired
    private ArticleService articleService;


    //添加一篇文章
    @RequestMapping(value = "/addArticle",method = RequestMethod.POST)
    @ResponseBody
    public void addArticle(Article article){
        this.articleService.addArticle(article);
    }
    //查询所有文章列表
    @RequestMapping(value = "/getAllArticle",method = RequestMethod.GET)
    @ResponseBody
    public List<Article> getAllArticle(){
        System.out.println("输出article"+this.articleService.getAllArticle());
        return this.articleService.getAllArticle();
    }
    //查询我的文章列表
    @RequestMapping(value = "/getMyArticle/{userId}",method = RequestMethod.GET)
    @ResponseBody
    public List<Article> getMyArticle(@PathVariable("userId") String userId){
        return this.articleService.getMyArticle(userId);
    }
    //删除一篇文章
    @RequestMapping(value = "/deleteArticle/{id}")
    @ResponseBody
    public void deleteArticle(@PathVariable("id") Integer id){
        this.articleService.delArticleById(id);
    }

    //修改文章信息
    @RequestMapping(value = "/modifyArticle/{id}")
    @ResponseBody
    public void modifyArticle(@PathVariable("id") Integer id){
        this.articleService.modifyMyArticle(id);
    }


    // 根据Name搜索文章
    @RequestMapping(value = "/searchByTitle/{title}",method = RequestMethod.GET)
    @ResponseBody
    public List<Article> searchByTitle(@PathVariable("title") String title){
        return this.articleService.searchByTitle(title);
    }



}
